from CvPythonExtensions import *
from WriterUtils import *

import CvScreenEnums
import CvUtil
import CvConfigParser
import CvPath
import os
import os.path
import Popup as PyPopup
import shutil 

# globals
gc = CyGlobalContext()
ArtFileMgr = CyArtFileMgr()
localText = CyTranslator()

# Change this to change the location where the resulting CIV4BuildingInfos.xml file 
# will be saved. So if the default value is left to "Test" then the 
# CIV4BuildingInfos.xml file would be written in a directory called "Test" inside 
# of the Tech Tree Editor mod folder.
# Default value is Test
g_strSaveDirectoryLocation = "Test"

# Change the value to false if the assets directory structure shouldn't be 
# created at the directory specified by the "Save Directory Location".
# Default value is True
g_bCreateAssetHierarchy = True

# Change the value to false if the changes made shouldn't be saved into the 
# assets directory for the tech editor. Changing it to false will require 
# manual copying of the saved files from the directory specified in the 
# "Save Directory Location" configurable option to the editor's asset directory 
# when wanting to edit existing mod files.
# Default value is True
g_bSaveChangesInEditorAssetsDirectory = True

def loadConfigurationValues():
	global g_strSaveDirectoryLocation
	global g_bCreateAssetHierarchy
	global g_bSaveChangesInEditorAssetsDirectory
	
	config = CvConfigParser.CvConfigParser("ViSa_v3.ini")

	if(config != None):
		g_strSaveDirectoryLocation = config.get("Tech Tree Editor", "Save Directory Location", "Test")
		g_bCreateAssetHierarchy = config.getboolean("Tech Tree Editor", "Create Asset Hierarchy", True)
		g_bSaveChangesInEditorAssetsDirectory = config.getboolean("Tech Tree Editor", "Save Changes In Editor Assets Directory", True)

		if(len(g_strSaveDirectoryLocation) == 0):
			g_strSaveDirectoryLocation = "Test"
			
class BuildingInfoWriter:
		
	def __init__(self):
		loadConfigurationValues()

	def isPrereqAndTechsDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range (gc.getDefineINT("NUM_BUILDING_AND_TECH_PREREQS")):
			if(objBuildingInfo.getPrereqAndTechs(iI) != TechTypes.NO_TECH):
				return true			
		return false

	def isPrereqOrBonusesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range (gc.getDefineINT("NUM_BUILDING_PREREQ_OR_BONUSES")):
			if(objBuildingInfo.getPrereqOrBonuses(iI) != BonusTypes.NO_BONUS):
				return true			
		return false
		
	def isProductionTraitDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range (gc.getNumTraitInfos()):
			if(objBuildingInfo.getProductionTraits(iI) != 0):
				return true				
		return false
		
	def isHappinessTraitDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range (gc.getNumTraitInfos()):
			if(objBuildingInfo.getHappinessTraits(iI) != 0):
				return true				
		return false

	def isSeaPlotYieldChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objBuildingInfo.getSeaPlotYieldChange(iI) != 0):
				return true
		return false
		
	def isGlobalSeaPlotYieldChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objBuildingInfo.getGlobalSeaPlotYieldChange(iI) != 0):
				return true
		return false
				
	def isYieldChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objBuildingInfo.getYieldChange(iI) != 0):
				return true
		return false
				
	def isYieldModifiersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objBuildingInfo.getYieldModifier(iI) != 0):
				return true
		return false
				
	def isPowerYieldModifiersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objBuildingInfo.getPowerYieldModifier(iI) != 0):
				return true
		return false
				
	def isAreaYieldModifiersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objBuildingInfo.getAreaYieldModifier(iI) != 0):
				return true
		return false
				
	def isGlobalYieldModifiersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objBuildingInfo.getGlobalYieldModifier(iI) != 0):
				return true
		return false
				
	def isCommerceChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.getCommerceChange(iI) != 0):
				return true
		return false
				
	def isObsoleteSafeCommerceChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.getObsoleteSafeCommerceChange(iI) != 0):
				return true
		return false
				
	def isCommerceChangeDoubleTimesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.getCommerceChangeDoubleTime(iI) != 0):
				return true
		return false

	def isCommerceModifiersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.getCommerceModifier(iI) != 0):
				return true
		return false

	def isGlobalCommerceModifiersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.getGlobalCommerceModifier(iI) != 0):
				return true
		return false

	def isSpecialistExtraCommercesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.getSpecialistExtraCommerce(iI) != 0):
				return true
		return false

	def isStateReligionCommercesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.getStateReligionCommerce(iI) != 0):
				return true
		return false
				
	def isCommerceHappinessDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.getCommerceHappiness(iI) != 0):
				return true
		return false

	def isReligionChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumReligionInfos()):
			if(objBuildingInfo.getReligionChange(iI) != 0):
				return true	
		return false

	def isSpecialistCountsDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumSpecialistInfos()):
			if(objBuildingInfo.getSpecialistCount(iI) != 0):
				return true	
		return false

	def isFreeSpecialistCountsDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumSpecialistInfos()):
			if(objBuildingInfo.getFreeSpecialistCount(iI) != 0):
				return true	
		return false

	def isCommerceFlexiblesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.isCommerceFlexible(iI)):
				return true
		return false

	def isCommerceChangeOriginalOwnersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objBuildingInfo.isCommerceChangeOriginalOwner(iI)):
				return true
		return false
						
	def isBonusHealthChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumBonusInfos()):
			if(objBuildingInfo.getBonusHealthChanges(iI) != 0):
				return true	
		return false
	
	def isUnitCombatFreeExperiencesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumUnitCombatInfos()):
			if(objBuildingInfo.getUnitCombatFreeExperience(iI) != 0):
				return true	
		return false
	
	def isDomainFreeExperiencesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(DomainTypes.NUM_DOMAIN_TYPES):
			if(objBuildingInfo.getDomainFreeExperience(iI) != 0):
				return true	
		return false
	
	def isDomainProductionModifiersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(DomainTypes.NUM_DOMAIN_TYPES):
			if(objBuildingInfo.getDomainProductionModifier(iI) != 0):
				return true	
		return false
						
	def isBonusHappinessChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumBonusInfos()):
			if(objBuildingInfo.getBonusHappinessChanges(iI) != 0):
				return true	
		return false
						
	def isBonusProductionModifiersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumBonusInfos()):
			if(objBuildingInfo.getBonusProductionModifier(iI) != 0):
				return true	
		return false
						
	def isBuildingHappinessChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumBuildingInfos()):
			if(objBuildingInfo.getBuildingHappinessChanges(iI) != 0):
				return true	
		return false
						
	def isPrereqBuildingClassesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumBuildingClassInfos()):
			if(objBuildingInfo.getPrereqNumOfBuildingClass(iI) != 0):
				return true	
		return false
														
	def isBuildingClassNeededsDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumBuildingClassInfos()):
			if(objBuildingInfo.isBuildingClassNeededInCity(iI)):
				return true	
		return false
						
	def isSpecialistYieldChangesDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumSpecialistInfos()):
			for iJ in range(YieldTypes.NUM_YIELD_TYPES):
				if(objBuildingInfo.getSpecialistYieldChange(iI, iJ) != 0):
					return true	
		return false
		
	def isSpecialistYieldChangeDefined(self, iBuilding, iSpecialist):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objBuildingInfo.getSpecialistYieldChange(iSpecialist, iI) != 0):
				return true	
		return false		

	def isBonusYieldModifiersDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumBonusInfos()):
			for iJ in range(YieldTypes.NUM_YIELD_TYPES):
				if(objBuildingInfo.getBonusYieldModifier(iI, iJ) != 0):
					return true	
		return false
								
	def isBonusYieldModifierDefined(self, iBuilding, iBonus):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objBuildingInfo.getBonusYieldModifier(iBonus, iI) != 0):
				return true	
		return false		

	def isFlavorsDefined(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		for iI in range(gc.getNumFlavorTypes()):
			if(objBuildingInfo.getFlavorValue(iI) != 0):
				return true	
		return false


	def printBuilding(self, iBuilding):
		objBuildingInfo = gc.getBuildingInfo(iBuilding)

		szText = ""
		
		szText = appendString(szText,"		<BuildingInfo>")
		
		szText = appendString(szText,"			<BuildingClass>%s</BuildingClass>" %(gc.getBuildingClassInfo(objBuildingInfo.getBuildingClassType()).getType()))		
		szText = appendString(szText,"			<Type>%s</Type>" %(objBuildingInfo.getType()))

		if(objBuildingInfo.getSpecialBuildingType() != -1):
			szText = appendString(szText,"			<SpecialBuildingType>%s</SpecialBuildingType>" %(gc.getSpecialBuildingInfo(objBuildingInfo.getSpecialBuildingType()).getType()))
		else:
			szText = appendString(szText,"			<SpecialBuildingType>NONE</SpecialBuildingType>")

		szText = appendString(szText,"			<Description>%s</Description>" %(objBuildingInfo.getTextKey()))
		szText = appendString(szText,"			<Civilopedia>%s</Civilopedia>" %(objBuildingInfo.getCivilopediaKey()))
		szText = appendString(szText,"			<Strategy>%s</Strategy>" %(objBuildingInfo.getStrategyKey()))
			
		if(objBuildingInfo.getAdvisorType() != -1):
			szText = appendString(szText,"			<Advisor>%s</Advisor>" %(gc.getAdvisorInfo(objBuildingInfo.getAdvisorType()).getType()))
		else:
			szText = appendString(szText,"			<Advisor>NONE</Advisor>")

		if(len(objBuildingInfo.getArtDefineTag()) > 0):
			szText = appendString(szText,"			<ArtDefineTag>%s</ArtDefineTag>" %(objBuildingInfo.getArtDefineTag()))
		else:
			szText = appendString(szText,"			<ArtDefineTag>NONE</ArtDefineTag>")

		if(len(objBuildingInfo.getMovieDefineTag()) > 0):
			szText = appendString(szText,"			<MovieDefineTag>%s</MovieDefineTag>" %(objBuildingInfo.getMovieDefineTag()))
		else:
			szText = appendString(szText,"			<MovieDefineTag>NONE</MovieDefineTag>")

		if(objBuildingInfo.getHolyCity() != -1):
			szText = appendString(szText,"			<HolyCity>%s</HolyCity>" %(gc.getReligionInfo(objBuildingInfo.getHolyCity()).getType()))
		else:
			szText = appendString(szText,"			<HolyCity>NONE</HolyCity>")

		if(objBuildingInfo.getReligionType() != -1):
			szText = appendString(szText,"			<ReligionType>%s</ReligionType>" %(gc.getReligionInfo(objBuildingInfo.getReligionType()).getType()))
		else:
			szText = appendString(szText,"			<ReligionType>NONE</ReligionType>")

		if(objBuildingInfo.getStateReligion() != -1):
			szText = appendString(szText,"			<StateReligion>%s</StateReligion>" %(gc.getReligionInfo(objBuildingInfo.getStateReligion()).getType()))
		else:
			szText = appendString(szText,"			<StateReligion>NONE</StateReligion>")

		if(objBuildingInfo.getPrereqReligion() != -1):
			szText = appendString(szText,"			<PrereqReligion>%s</PrereqReligion>" %(gc.getReligionInfo(objBuildingInfo.getPrereqReligion()).getType()))
		else:
			szText = appendString(szText,"			<PrereqReligion>NONE</PrereqReligion>")

		if(objBuildingInfo.getGlobalReligionCommerce() != -1):
			szText = appendString(szText,"			<GlobalReligionCommerce>%s</GlobalReligionCommerce>" %(gc.getReligionInfo(objBuildingInfo.getGlobalReligionCommerce()).getType()))
		else:
			szText = appendString(szText,"			<GlobalReligionCommerce>NONE</GlobalReligionCommerce>")

		if(objBuildingInfo.getVictoryPrereq() != -1):
			szText = appendString(szText,"			<VictoryPrereq>%s</VictoryPrereq>" %(gc.getVictoryInfo(objBuildingInfo.getVictoryPrereq()).getType()))
		else:
			szText = appendString(szText,"			<VictoryPrereq>NONE</VictoryPrereq>")

		if(objBuildingInfo.getFreeStartEra() != -1):
			szText = appendString(szText,"			<FreeStartEra>%s</FreeStartEra>" %(gc.getEraInfo(objBuildingInfo.getFreeStartEra()).getType()))
		else:
			szText = appendString(szText,"			<FreeStartEra>NONE</FreeStartEra>")

		if(objBuildingInfo.getMaxStartEra() != -1):
			szText = appendString(szText,"			<MaxStartEra>%s</MaxStartEra>" %(gc.getEraInfo(objBuildingInfo.getMaxStartEra()).getType()))
		else:
			szText = appendString(szText,"			<MaxStartEra>NONE</MaxStartEra>")

		if(objBuildingInfo.getObsoleteTech() != -1):
			szText = appendString(szText,"			<ObsoleteTech>%s</ObsoleteTech>" %(gc.getTechInfo(objBuildingInfo.getObsoleteTech()).getType()))
		else:
			szText = appendString(szText,"			<ObsoleteTech>NONE</ObsoleteTech>")

		if(objBuildingInfo.getPrereqAndTech() != -1):
			szText = appendString(szText,"			<PrereqTech>%s</PrereqTech>" %(gc.getTechInfo(objBuildingInfo.getPrereqAndTech()).getType()))
		else:
			szText = appendString(szText,"			<PrereqTech>NONE</PrereqTech>")

		if(self.isPrereqAndTechsDefined(iBuilding)):
			szText = appendString(szText,"			<TechTypes>")
			for iI in range (gc.getDefineINT("NUM_BUILDING_AND_TECH_PREREQS")):
				if(objBuildingInfo.getPrereqAndTechs(iI) != TechTypes.NO_TECH):
					szText = appendString(szText,"				<PrereqTech>%s</PrereqTech>" %(gc.getTechInfo(objBuildingInfo.getPrereqAndTechs(iI)).getType()))
			szText = appendString(szText,"			</TechTypes>")
		else:
			szText = appendString(szText,"			<TechTypes/>")

		if(objBuildingInfo.getPrereqAndBonus() != -1):
			szText = appendString(szText,"			<Bonus>%s</Bonus>" %(gc.getBonusInfo(objBuildingInfo.getPrereqAndBonus()).getType()))
		else:
			szText = appendString(szText,"			<Bonus>NONE</Bonus>")

		if(self.isPrereqOrBonusesDefined(iBuilding)):
			szText = appendString(szText,"			<PrereqBonuses>")
			for iI in range (gc.getDefineINT("NUM_BUILDING_PREREQ_OR_BONUSES")):
				if(objBuildingInfo.getPrereqOrBonuses(iI) != BonusTypes.NO_BONUS):
					szText = appendString(szText,"				<Bonus>%s</Bonus>" %(gc.getBonusInfo(objBuildingInfo.getPrereqOrBonuses(iI)).getType()))
			szText = appendString(szText,"			</PrereqBonuses>")
		else:
			szText = appendString(szText,"			<PrereqBonuses/>")

		if(self.isProductionTraitDefined(iBuilding)):
			szText = appendString(szText,"			<ProductionTraits>")
			for iI in range (gc.getNumTraitInfos()):
				if(gc.getBuildingInfo(iBuilding).getProductionTraits(iI) > 0):
					szText = appendString(szText,"				<ProductionTrait>")
					szText = appendString(szText,"					<ProductionTraitType>%s</ProductionTraitType>" %(gc.getTraitInfo(iI).getType()))
					szText = appendString(szText,"					<iProductionTrait>%s</iProductionTrait>" %(gc.getBuildingInfo(iBuilding).getProductionTraits(iI)))
					szText = appendString(szText,"				</ProductionTrait>")
			szText = appendString(szText,"			</ProductionTraits>")
		else:
			szText = appendString(szText,"			<ProductionTraits/>")

		if(self.isHappinessTraitDefined(iBuilding)):
			szText = appendString(szText,"			<HappinessTraits>")
			for iI in range (gc.getNumTraitInfos()):
				if(gc.getBuildingInfo(iBuilding).getHappinessTraits(iI) > 0):
					szText = appendString(szText,"				<HappinessTrait>")
					szText = appendString(szText,"					<HappinessTraitType>%s</HappinessTraitType>" %(gc.getTraitInfo(iI).getType()))
					szText = appendString(szText,"					<iHappinessTrait>%s</iHappinessTrait>" %(gc.getBuildingInfo(iBuilding).getHappinessTraits(iI)))
					szText = appendString(szText,"				</HappinessTrait>")
			szText = appendString(szText,"			</HappinessTraits>")
		else:
			szText = appendString(szText,"			<HappinessTraits/>")

		if(objBuildingInfo.getPowerBonus() != -1):
			szText = appendString(szText,"			<PowerBonus>%s</PowerBonus>" %(gc.getBonusInfo(objBuildingInfo.getPowerBonus()).getType()))
		else:
			szText = appendString(szText,"			<PowerBonus>NONE</PowerBonus>")

		if(objBuildingInfo.getFreeBonus() != -1):
			szText = appendString(szText,"			<FreeBonus>%s</FreeBonus>" %(gc.getBonusInfo(objBuildingInfo.getFreeBonus()).getType()))
		else:
			szText = appendString(szText,"			<FreeBonus>NONE</FreeBonus>")
			
		szText = appendString(szText,"			<iNumFreeBonuses>%s</iNumFreeBonuses>" %(objBuildingInfo.getNumFreeBonuses()))
			
		if(objBuildingInfo.getFreeBuildingClass() != -1):
			szText = appendString(szText,"			<FreeBuilding>%s</FreeBuilding>" %(gc.getBuildingClassInfo(objBuildingInfo.getFreeBuildingClass()).getType()))
		else:
			szText = appendString(szText,"			<FreeBuilding>NONE</FreeBuilding>")

		if(objBuildingInfo.getFreePromotion() != -1):
			szText = appendString(szText,"			<FreePromotion>%s</FreePromotion>" %(gc.getPromotionInfo(objBuildingInfo.getFreePromotion()).getType()))
		else:
			szText = appendString(szText,"			<FreePromotion>NONE</FreePromotion>")

		if(objBuildingInfo.getCivic() != -1):
			szText = appendString(szText,"			<CivicOption>%s</CivicOption>" %(gc.getCivicOptionInfo(objBuildingInfo.getCivic()).getType()))
		else:
			szText = appendString(szText,"			<CivicOption>NONE</CivicOption>")

		if(objBuildingInfo.getGreatPeopleUnitClass() != -1):
			szText = appendString(szText,"			<GreatPeopleUnitClass>%s</GreatPeopleUnitClass>" %(gc.getUnitClassInfo(objBuildingInfo.getGreatPeopleUnitClass()).getType()))
		else:
			szText = appendString(szText,"			<GreatPeopleUnitClass>NONE</GreatPeopleUnitClass>")

		szText = appendString(szText,"			<iGreatPeopleRateChange>%s</iGreatPeopleRateChange>" %(objBuildingInfo.getGreatPeopleRateChange()))
		szText = appendString(szText,"			<iHurryAngerModifier>%s</iHurryAngerModifier>" %(objBuildingInfo.getHurryAngerModifier()))

		szText = appendString(szText,"			<bBorderObstacle>%s</bBorderObstacle>" %(boolToInt(objBuildingInfo.isAreaBorderObstacle())))
		szText = appendString(szText,"			<bTeamShare>%s</bTeamShare>" %(boolToInt(objBuildingInfo.isTeamShare())))
		szText = appendString(szText,"			<bWater>%s</bWater>" %(boolToInt(objBuildingInfo.isWater())))
		szText = appendString(szText,"			<bRiver>%s</bRiver>" %(boolToInt(objBuildingInfo.isRiver())))
		szText = appendString(szText,"			<bPower>%s</bPower>" %(boolToInt(objBuildingInfo.isPower())))
		szText = appendString(szText,"			<bDirtyPower>%s</bDirtyPower>" %(boolToInt(objBuildingInfo.isDirtyPower())))
		szText = appendString(szText,"			<bAreaCleanPower>%s</bAreaCleanPower>" %(boolToInt(objBuildingInfo.isAreaCleanPower())))
		szText = appendString(szText,"			<bDiploVote>%s</bDiploVote>" %(boolToInt(objBuildingInfo.isDiploVote())))
		szText = appendString(szText,"			<bForceTeamVoteEligible>%s</bForceTeamVoteEligible>" %(boolToInt(objBuildingInfo.isForceTeamVoteEligible())))
		szText = appendString(szText,"			<bCapital>%s</bCapital>" %(boolToInt(objBuildingInfo.isCapital())))
		szText = appendString(szText,"			<bGovernmentCenter>%s</bGovernmentCenter>" %(boolToInt(objBuildingInfo.isGovernmentCenter())))
		szText = appendString(szText,"			<bGoldenAge>%s</bGoldenAge>" %(boolToInt(objBuildingInfo.isGoldenAge())))
		szText = appendString(szText,"			<bMapCentering>%s</bMapCentering>" %(boolToInt(objBuildingInfo.isMapCentering())))
		szText = appendString(szText,"			<bNoUnhappiness>%s</bNoUnhappiness>" %(boolToInt(objBuildingInfo.isNoUnhappiness())))
		szText = appendString(szText,"			<bNoUnhealthyPopulation>%s</bNoUnhealthyPopulation>" %(boolToInt(objBuildingInfo.isNoUnhealthyPopulation())))
		szText = appendString(szText,"			<bBuildingOnlyHealthy>%s</bBuildingOnlyHealthy>" %(boolToInt(objBuildingInfo.isBuildingOnlyHealthy())))
		szText = appendString(szText,"			<bNeverCapture>%s</bNeverCapture>" %(boolToInt(objBuildingInfo.isNeverCapture())))
		szText = appendString(szText,"			<bNukeImmune>%s</bNukeImmune>" %(boolToInt(objBuildingInfo.isNukeImmune())))
		szText = appendString(szText,"			<bPrereqReligion>%s</bPrereqReligion>" %(boolToInt(objBuildingInfo.isPrereqReligion())))
		szText = appendString(szText,"			<bCenterInCity>%s</bCenterInCity>" %(boolToInt(objBuildingInfo.isCenterInCity())))

		szText = appendString(szText,"			<iAIWeight>%s</iAIWeight>" %(objBuildingInfo.getAIWeight()))
		szText = appendString(szText,"			<iCost>%s</iCost>" %(objBuildingInfo.getProductionCost()))
		szText = appendString(szText,"			<iHurryCostModifier>%s</iHurryCostModifier>" %(objBuildingInfo.getHurryCostModifier()))
		szText = appendString(szText,"			<iMinAreaSize>%s</iMinAreaSize>" %(objBuildingInfo.getMinAreaSize()))
		szText = appendString(szText,"			<iConquestProb>%s</iConquestProb>" %(objBuildingInfo.getConquestProbability()))
		szText = appendString(szText,"			<iCitiesPrereq>%s</iCitiesPrereq>" %(objBuildingInfo.getNumCitiesPrereq()))
		szText = appendString(szText,"			<iTeamsPrereq>%s</iTeamsPrereq>" %(objBuildingInfo.getNumTeamsPrereq()))
		szText = appendString(szText,"			<iLevelPrereq>%s</iLevelPrereq>" %(objBuildingInfo.getUnitLevelPrereq()))
		szText = appendString(szText,"			<iMinLatitude>%s</iMinLatitude>" %(objBuildingInfo.getMinLatitude()))
		szText = appendString(szText,"			<iMaxLatitude>%s</iMaxLatitude>" %(objBuildingInfo.getMaxLatitude()))
		szText = appendString(szText,"			<iGreatPeopleRateModifier>%s</iGreatPeopleRateModifier>" %(objBuildingInfo.getGreatPeopleRateModifier()))
		szText = appendString(szText,"			<iGreatGeneralRateModifier>%s</iGreatGeneralRateModifier>" %(objBuildingInfo.getGreatGeneralRateModifier()))
		szText = appendString(szText,"			<iDomesticGreatGeneralRateModifier>%s</iDomesticGreatGeneralRateModifier>" %(objBuildingInfo.getDomesticGreatGeneralRateModifier()))
		szText = appendString(szText,"			<iGlobalGreatPeopleRateModifier>%s</iGlobalGreatPeopleRateModifier>" %(objBuildingInfo.getGlobalGreatPeopleRateModifier()))
		szText = appendString(szText,"			<iAnarchyModifier>%s</iAnarchyModifier>" %(objBuildingInfo.getAnarchyModifier()))
		szText = appendString(szText,"			<iGlobalHurryModifier>%s</iGlobalHurryModifier>" %(objBuildingInfo.getGlobalHurryModifier()))
		szText = appendString(szText,"			<iExperience>%s</iExperience>" %(objBuildingInfo.getFreeExperience()))
		szText = appendString(szText,"			<iGlobalExperience>%s</iGlobalExperience>" %(objBuildingInfo.getGlobalFreeExperience()))
		szText = appendString(szText,"			<iFoodKept>%s</iFoodKept>" %(objBuildingInfo.getFoodKept()))
		szText = appendString(szText,"			<iAirlift>%s</iAirlift>" %(objBuildingInfo.getAirlift()))
		szText = appendString(szText,"			<iAirModifier>%s</iAirModifier>" %(objBuildingInfo.getAirModifier()))
		szText = appendString(szText,"			<iNukeModifier>%s</iNukeModifier>" %(objBuildingInfo.getNukeModifier()))
		szText = appendString(szText,"			<iNukeExplosionRand>%s</iNukeExplosionRand>" %(objBuildingInfo.getNukeExplosionRand()))
		szText = appendString(szText,"			<iFreeSpecialist>%s</iFreeSpecialist>" %(objBuildingInfo.getFreeSpecialist()))
		szText = appendString(szText,"			<iAreaFreeSpecialist>%s</iAreaFreeSpecialist>" %(objBuildingInfo.getAreaFreeSpecialist()))
		szText = appendString(szText,"			<iGlobalFreeSpecialist>%s</iGlobalFreeSpecialist>" %(objBuildingInfo.getGlobalFreeSpecialist()))
		szText = appendString(szText,"			<iMaintenanceModifier>%s</iMaintenanceModifier>" %(objBuildingInfo.getMaintenanceModifier()))
		szText = appendString(szText,"			<iWarWearinessModifier>%s</iWarWearinessModifier>" %(objBuildingInfo.getWarWearinessModifier()))
		szText = appendString(szText,"			<iGlobalWarWearinessModifier>%s</iGlobalWarWearinessModifier>" %(objBuildingInfo.getGlobalWarWearinessModifier()))
		szText = appendString(szText,"			<iHealRateChange>%s</iHealRateChange>" %(objBuildingInfo.getHealRateChange()))
		szText = appendString(szText,"			<iHealth>%s</iHealth>" %(objBuildingInfo.getHealth()))
		szText = appendString(szText,"			<iAreaHealth>%s</iAreaHealth>" %(objBuildingInfo.getAreaHealth()))
		szText = appendString(szText,"			<iGlobalHealth>%s</iGlobalHealth>" %(objBuildingInfo.getGlobalHealth()))
		szText = appendString(szText,"			<iHappiness>%s</iHappiness>" %(objBuildingInfo.getHappiness()))
		szText = appendString(szText,"			<iAreaHappiness>%s</iAreaHappiness>" %(objBuildingInfo.getAreaHappiness()))
		szText = appendString(szText,"			<iGlobalHappiness>%s</iGlobalHappiness>" %(objBuildingInfo.getGlobalHappiness()))
		szText = appendString(szText,"			<iStateReligionHappiness>%s</iStateReligionHappiness>" %(objBuildingInfo.getStateReligionHappiness()))
		szText = appendString(szText,"			<iWorkerSpeedModifier>%s</iWorkerSpeedModifier>" %(objBuildingInfo.getWorkerSpeedModifier()))
		szText = appendString(szText,"			<iMilitaryProductionModifier>%s</iMilitaryProductionModifier>" %(objBuildingInfo.getMilitaryProductionModifier()))
		szText = appendString(szText,"			<iSpaceProductionModifier>%s</iSpaceProductionModifier>" %(objBuildingInfo.getSpaceProductionModifier()))
		szText = appendString(szText,"			<iGlobalSpaceProductionModifier>%s</iGlobalSpaceProductionModifier>" %(objBuildingInfo.getGlobalSpaceProductionModifier()))
		szText = appendString(szText,"			<iTradeRoutes>%s</iTradeRoutes>" %(objBuildingInfo.getTradeRoutes()))
		szText = appendString(szText,"			<iCoastalTradeRoutes>%s</iCoastalTradeRoutes>" %(objBuildingInfo.getCoastalTradeRoutes()))
		szText = appendString(szText,"			<iGlobalTradeRoutes>%s</iGlobalTradeRoutes>" %(objBuildingInfo.getGlobalTradeRoutes()))
		szText = appendString(szText,"			<iTradeRouteModifier>%s</iTradeRouteModifier>" %(objBuildingInfo.getTradeRouteModifier()))
		szText = appendString(szText,"			<iGlobalPopulationChange>%s</iGlobalPopulationChange>" %(objBuildingInfo.getGlobalPopulationChange()))
		szText = appendString(szText,"			<iFreeTechs>%s</iFreeTechs>" %(objBuildingInfo.getFreeTechs()))
		szText = appendString(szText,"			<iDefense>%s</iDefense>" %(objBuildingInfo.getDefenseModifier()))
		szText = appendString(szText,"			<iBombardDefense>%s</iBombardDefense>" %(objBuildingInfo.getBombardDefenseModifier()))
		szText = appendString(szText,"			<iAllCityDefense>%s</iAllCityDefense>" %(objBuildingInfo.getAllCityDefenseModifier()))
		szText = appendString(szText,"			<iAsset>%s</iAsset>" %(objBuildingInfo.getAssetValue()))
		szText = appendString(szText,"			<iPower>%s</iPower>" %(objBuildingInfo.getPowerValue()))

		szText = appendString(szText,"			<fVisibilityPriority>%s</fVisibilityPriority>" %(objBuildingInfo.getVisibilityPriority()))

		if(self.isSeaPlotYieldChangesDefined(iBuilding)):
			szText = appendString(szText,"			<SeaPlotYieldChanges>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objBuildingInfo.getSeaPlotYieldChange(iI)))
			szText = appendString(szText,"			</SeaPlotYieldChanges>")
		else:
			szText = appendString(szText,"			<SeaPlotYieldChanges/>")

		if(self.isGlobalSeaPlotYieldChangesDefined(iBuilding)):
			szText = appendString(szText,"			<GlobalSeaPlotYieldChanges>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objBuildingInfo.getGlobalSeaPlotYieldChange(iI)))
			szText = appendString(szText,"			</GlobalSeaPlotYieldChanges>")
		else:
			szText = appendString(szText,"			<GlobalSeaPlotYieldChanges/>")

		if(self.isYieldChangesDefined(iBuilding)):
			szText = appendString(szText,"			<YieldChanges>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objBuildingInfo.getYieldChange(iI)))
			szText = appendString(szText,"			</YieldChanges>")
		else:
			szText = appendString(szText,"			<YieldChanges/>")

		if(self.isYieldModifiersDefined(iBuilding)):
			szText = appendString(szText,"			<YieldModifiers>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objBuildingInfo.getYieldModifier(iI)))
			szText = appendString(szText,"			</YieldModifiers>")
#		else:
#			szText = appendString(szText,"			<YieldModifiers/>")

		if(self.isPowerYieldModifiersDefined(iBuilding)):
			szText = appendString(szText,"			<PowerYieldModifiers>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objBuildingInfo.getPowerYieldModifier(iI)))
			szText = appendString(szText,"			</PowerYieldModifiers>")
#		else:
#			szText = appendString(szText,"			<PowerYieldModifiers/>")

		if(self.isAreaYieldModifiersDefined(iBuilding)):
			szText = appendString(szText,"			<AreaYieldModifiers>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objBuildingInfo.getAreaYieldModifier(iI)))
			szText = appendString(szText,"			</AreaYieldModifiers>")
#		else:
#			szText = appendString(szText,"			<AreaYieldModifiers/>")

		if(self.isGlobalYieldModifiersDefined(iBuilding)):
			szText = appendString(szText,"			<GlobalYieldModifiers>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objBuildingInfo.getGlobalYieldModifier(iI)))
			szText = appendString(szText,"			</GlobalYieldModifiers>")
#		else:
#			szText = appendString(szText,"			<GlobalYieldModifiers/>")
			
		if(self.isCommerceChangesDefined(iBuilding)):
			szText = appendString(szText,"			<CommerceChanges>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objBuildingInfo.getCommerceChange(iI)))
			szText = appendString(szText,"			</CommerceChanges>")
		else:
			szText = appendString(szText,"			<CommerceChanges/>")
			
		if(self.isObsoleteSafeCommerceChangesDefined(iBuilding)):
			szText = appendString(szText,"			<ObsoleteSafeCommerceChanges>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objBuildingInfo.getObsoleteSafeCommerceChange(iI)))
			szText = appendString(szText,"			</ObsoleteSafeCommerceChanges>")
		else:
			szText = appendString(szText,"			<ObsoleteSafeCommerceChanges/>")
			
		if(self.isCommerceChangeDoubleTimesDefined(iBuilding)):
			szText = appendString(szText,"			<CommerceChangeDoubleTimes>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objBuildingInfo.getCommerceChangeDoubleTime(iI)))
			szText = appendString(szText,"			</CommerceChangeDoubleTimes>")
		else:
			szText = appendString(szText,"			<CommerceChangeDoubleTimes/>")

		if(self.isCommerceModifiersDefined(iBuilding)):
			szText = appendString(szText,"			<CommerceModifiers>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objBuildingInfo.getCommerceModifier(iI)))
			szText = appendString(szText,"			</CommerceModifiers>")
		else:
			szText = appendString(szText,"			<CommerceModifiers/>")

		if(self.isGlobalCommerceModifiersDefined(iBuilding)):
			szText = appendString(szText,"			<GlobalCommerceModifiers>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objBuildingInfo.getGlobalCommerceModifier(iI)))
			szText = appendString(szText,"			</GlobalCommerceModifiers>")
		else:
			szText = appendString(szText,"			<GlobalCommerceModifiers/>")

		if(self.isSpecialistExtraCommercesDefined(iBuilding)):
			szText = appendString(szText,"			<SpecialistExtraCommerces>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objBuildingInfo.getSpecialistExtraCommerce(iI)))
			szText = appendString(szText,"			</SpecialistExtraCommerces>")
		else:
			szText = appendString(szText,"			<SpecialistExtraCommerces/>")

		if(self.isStateReligionCommercesDefined(iBuilding)):
			szText = appendString(szText,"			<StateReligionCommerces>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objBuildingInfo.getStateReligionCommerce(iI)))
			szText = appendString(szText,"			</StateReligionCommerces>")
		else:
			szText = appendString(szText,"			<StateReligionCommerces/>")

		if(self.isCommerceHappinessDefined(iBuilding)):
			szText = appendString(szText,"			<CommerceHappinesses>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objBuildingInfo.getCommerceHappiness(iI)))
			szText = appendString(szText,"			</CommerceHappinesses>")
		else:
			szText = appendString(szText,"			<CommerceHappinesses/>")
												
		if(self.isReligionChangesDefined(iBuilding)):
			szText = appendString(szText,"			<ReligionChanges>")
			for iI in range(gc.getNumReligionInfos()):
				if(objBuildingInfo.getReligionChange(iI) != 0):
					szText = appendString(szText,"				<ReligionChange>")
					szText = appendString(szText,"					<ReligionType>%s</ReligionType>" %(gc.getReligionInfo(iI).getType()))
					szText = appendString(szText,"					<iReligionChange>%s</iReligionChange>" %(objBuildingInfo.getReligionChange(iI)))
					szText = appendString(szText,"				</ReligionChange>")
			szText = appendString(szText,"			</ReligionChanges>")
		else:
			szText = appendString(szText,"			<ReligionChanges/>")
							
		if(self.isSpecialistCountsDefined(iBuilding)):
			szText = appendString(szText,"			<SpecialistCounts>")
			for iI in range(gc.getNumSpecialistInfos()):
				if(objBuildingInfo.getSpecialistCount(iI) != 0):
					szText = appendString(szText,"				<SpecialistCount>")
					szText = appendString(szText,"					<SpecialistType>%s</SpecialistType>" %(gc.getSpecialistInfo(iI).getType()))
					szText = appendString(szText,"					<iSpecialistCount>%s</iSpecialistCount>" %(objBuildingInfo.getSpecialistCount(iI)))
					szText = appendString(szText,"				</SpecialistCount>")
			szText = appendString(szText,"			</SpecialistCounts>")
		else:
			szText = appendString(szText,"			<SpecialistCounts/>")

		if(self.isFreeSpecialistCountsDefined(iBuilding)):
			szText = appendString(szText,"			<FreeSpecialistCounts>")
			for iI in range(gc.getNumSpecialistInfos()):
				if(objBuildingInfo.getFreeSpecialistCount(iI) != 0):
					szText = appendString(szText,"				<FreeSpecialistCount>")
					szText = appendString(szText,"					<SpecialistType>%s</SpecialistType>" %(gc.getSpecialistInfo(iI).getType()))
					szText = appendString(szText,"					<iFreeSpecialistCount>%s</iFreeSpecialistCount>" %(objBuildingInfo.getFreeSpecialistCount(iI)))
					szText = appendString(szText,"				</FreeSpecialistCount>")
			szText = appendString(szText,"			</FreeSpecialistCounts>")
		else:
			szText = appendString(szText,"			<FreeSpecialistCounts/>")

		if(self.isCommerceFlexiblesDefined(iBuilding)):
			szText = appendString(szText,"			<CommerceFlexibles>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<bCommerce>%s</bCommerce>" %(boolToInt(objBuildingInfo.isCommerceFlexible(iI))))
			szText = appendString(szText,"			</CommerceFlexibles>")
		else:
			szText = appendString(szText,"			<CommerceFlexibles/>")
			
		if(self.isCommerceChangeOriginalOwnersDefined(iBuilding)):
			szText = appendString(szText,"			<CommerceChangeOriginalOwners>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<bCommerceChangeOriginalOwner>%s</bCommerceChangeOriginalOwner>" %(boolToInt(objBuildingInfo.isCommerceChangeOriginalOwner(iI))))
			szText = appendString(szText,"			</CommerceChangeOriginalOwners>")
		else:
			szText = appendString(szText,"			<CommerceChangeOriginalOwners/>")
							
		if(len(objBuildingInfo.getConstructSound()) > 0):
			szText = appendString(szText,"			<ConstructSound>%s</ConstructSound>" %(objBuildingInfo.getConstructSound()))
		else:
			szText = appendString(szText,"			<ConstructSound/>")
															
		if(self.isBonusHealthChangesDefined(iBuilding)):
			szText = appendString(szText,"			<BonusHealthChanges>")
			for iI in range(gc.getNumBonusInfos()):
				if(objBuildingInfo.getBonusHealthChanges(iI) != 0):
					szText = appendString(szText,"				<BonusHealthChange>")
					szText = appendString(szText,"					<BonusType>%s</BonusType>" %(gc.getBonusInfo(iI).getType()))
					szText = appendString(szText,"					<iHealthChange>%s</iHealthChange>" %(objBuildingInfo.getBonusHealthChanges(iI)))
					szText = appendString(szText,"				</BonusHealthChange>")
			szText = appendString(szText,"			</BonusHealthChanges>")
		else:
			szText = appendString(szText,"			<BonusHealthChanges/>")
															
		if(self.isBonusHappinessChangesDefined(iBuilding)):
			szText = appendString(szText,"			<BonusHappinessChanges>")
			for iI in range(gc.getNumBonusInfos()):
				if(objBuildingInfo.getBonusHappinessChanges(iI) != 0):
					szText = appendString(szText,"				<BonusHappinessChange>")
					szText = appendString(szText,"					<BonusType>%s</BonusType>" %(gc.getBonusInfo(iI).getType()))
					szText = appendString(szText,"					<iHappinessChange>%s</iHappinessChange>" %(objBuildingInfo.getBonusHappinessChanges(iI)))
					szText = appendString(szText,"				</BonusHappinessChange>")
			szText = appendString(szText,"			</BonusHappinessChanges>")
		else:
			szText = appendString(szText,"			<BonusHappinessChanges/>")
															
		if(self.isBonusProductionModifiersDefined(iBuilding)):
			szText = appendString(szText,"			<BonusProductionModifiers>")
			for iI in range(gc.getNumBonusInfos()):
				if(objBuildingInfo.getBonusProductionModifier(iI) != 0):
					szText = appendString(szText,"				<BonusProductionModifier>")
					szText = appendString(szText,"					<BonusType>%s</BonusType>" %(gc.getBonusInfo(iI).getType()))
					szText = appendString(szText,"					<iProductonModifier>%s</iProductonModifier>" %(objBuildingInfo.getBonusProductionModifier(iI)))
					szText = appendString(szText,"				</BonusProductionModifier>")
			szText = appendString(szText,"			</BonusProductionModifiers>")
		else:
			szText = appendString(szText,"			<BonusProductionModifiers/>")

		if(self.isUnitCombatFreeExperiencesDefined(iBuilding)):
			szText = appendString(szText,"			<UnitCombatFreeExperiences>")
			for iI in range(gc.getNumUnitCombatInfos()):
				if(objBuildingInfo.getUnitCombatFreeExperience(iI) != 0):
					szText = appendString(szText,"				<UnitCombatFreeExperience>")
					szText = appendString(szText,"					<UnitCombatType>%s</UnitCombatType>" %(gc.getUnitCombatInfo(iI).getType()))
					szText = appendString(szText,"					<iExperience>%s</iExperience>" %(objBuildingInfo.getUnitCombatFreeExperience(iI)))
					szText = appendString(szText,"				</UnitCombatFreeExperience>")
			szText = appendString(szText,"			</UnitCombatFreeExperiences>")
		else:
			szText = appendString(szText,"			<UnitCombatFreeExperiences/>")

		if(self.isDomainFreeExperiencesDefined(iBuilding)):
			szText = appendString(szText,"			<DomainFreeExperiences>")
			for iI in range(DomainTypes.NUM_DOMAIN_TYPES):
				if(objBuildingInfo.getDomainFreeExperience(iI) != 0):
					szText = appendString(szText,"				<DomainFreeExperience>")
					szText = appendString(szText,"					<DomainType>%s</DomainType>" %(gc.getDomainInfo(iI).getType()))
					szText = appendString(szText,"					<iExperience>%s</iExperience>" %(objBuildingInfo.getDomainFreeExperience(iI)))
					szText = appendString(szText,"				</DomainFreeExperience>")
			szText = appendString(szText,"			</DomainFreeExperiences>")
		else:
			szText = appendString(szText,"			<DomainFreeExperiences/>")

		if(self.isDomainProductionModifiersDefined(iBuilding)):
			szText = appendString(szText,"			<DomainProductionModifiers>")
			for iI in range(DomainTypes.NUM_DOMAIN_TYPES):
				if(objBuildingInfo.getDomainProductionModifier(iI) != 0):
					szText = appendString(szText,"				<DomainProductionModifier>")
					szText = appendString(szText,"					<DomainType>%s</DomainType>" %(gc.getDomainInfo(iI).getType()))
					szText = appendString(szText,"					<iProductionModifier>%s</iProductionModifier>" %(objBuildingInfo.getDomainProductionModifier(iI)))
					szText = appendString(szText,"				</DomainProductionModifier>")
			szText = appendString(szText,"			</DomainProductionModifiers>")
		else:
			szText = appendString(szText,"			<DomainProductionModifiers/>")

		if(self.isBuildingHappinessChangesDefined(iBuilding)):
			szText = appendString(szText,"			<BuildingHappinessChanges>")
			for iI in range(gc.getNumBuildingInfos()):
				if(objBuildingInfo.getBuildingHappinessChanges(iI) != 0):
					szText = appendString(szText,"				<BuildingHappinessChange>")
					szText = appendString(szText,"					<BuildingType>%s</BuildingType>" %(gc.getBuildingInfo(iI).getType()))
					szText = appendString(szText,"					<iHappinessChange>%s</iHappinessChange>" %(objBuildingInfo.getBuildingHappinessChanges(iI)))
					szText = appendString(szText,"				</BuildingHappinessChange>")
			szText = appendString(szText,"			</BuildingHappinessChanges>")
		else:
			szText = appendString(szText,"			<BuildingHappinessChanges/>")

		if(self.isPrereqBuildingClassesDefined(iBuilding)):
			szText = appendString(szText,"			<PrereqBuildingClasses>")
			for iI in range(gc.getNumBuildingClassInfos()):
				if(objBuildingInfo.getPrereqNumOfBuildingClass(iI) != 0):
					szText = appendString(szText,"				<PrereqBuildingClass>")
					szText = appendString(szText,"					<BuildingClassType>%s</BuildingClassType>" %(gc.getBuildingClassInfo(iI).getType()))
					szText = appendString(szText,"					<iNumBuildingNeeded>%s</iNumBuildingNeeded>" %(objBuildingInfo.getPrereqNumOfBuildingClass(iI)))
					szText = appendString(szText,"				</PrereqBuildingClass>")
			szText = appendString(szText,"			</PrereqBuildingClasses>")
		else:
			szText = appendString(szText,"			<PrereqBuildingClasses/>")

		if(self.isBuildingClassNeededsDefined(iBuilding)):
			szText = appendString(szText,"			<BuildingClassNeededs>")
			for iI in range(gc.getNumBuildingClassInfos()):
				if(objBuildingInfo.isBuildingClassNeededInCity(iI)):
					szText = appendString(szText,"				<BuildingClassNeeded>")
					szText = appendString(szText,"					<BuildingClassType>%s</BuildingClassType>" %(gc.getBuildingClassInfo(iI).getType()))
					szText = appendString(szText,"					<bNeededInCity>%s</bNeededInCity>" %(boolToInt(objBuildingInfo.isBuildingClassNeededInCity(iI))))
					szText = appendString(szText,"				</BuildingClassNeeded>")
			szText = appendString(szText,"			</BuildingClassNeededs>")
		else:
			szText = appendString(szText,"			<BuildingClassNeededs/>")

		if(self.isSpecialistYieldChangesDefined(iBuilding)):
			szText = appendString(szText,"			<SpecialistYieldChanges>")
			for iI in range(gc.getNumSpecialistInfos()):
				if(self.isSpecialistYieldChangeDefined(iBuilding, iI)):
					szText = appendString(szText,"				<SpecialistYieldChange>")
					szText = appendString(szText,"					<SpecialistType>%s</SpecialistType>" %(gc.getSpecialistInfo(iI).getType()))
					szText = appendString(szText,"					<YieldChanges>")
					for iJ in range(YieldTypes.NUM_YIELD_TYPES):
						szText = appendString(szText,"						<iYield>%s</iYield>" %(objBuildingInfo.getSpecialistYieldChange(iI, iJ)))
					szText = appendString(szText,"					</YieldChanges>")
					szText = appendString(szText,"				</SpecialistYieldChange>")
			szText = appendString(szText,"			</SpecialistYieldChanges>")
		else:
			szText = appendString(szText,"			<SpecialistYieldChanges/>")

		if(self.isBonusYieldModifiersDefined(iBuilding)):
			szText = appendString(szText,"			<BonusYieldModifiers>")
			for iI in range(gc.getNumBonusInfos()):
				if(self.isBonusYieldModifierDefined(iBuilding, iI)):
					szText = appendString(szText,"				<BonusYieldModifier>")
					szText = appendString(szText,"					<BonusType>%s</BonusType>" %(gc.getBonusInfo(iI).getType()))
					szText = appendString(szText,"					<YieldModifiers>")
					for iJ in range(YieldTypes.NUM_YIELD_TYPES):
						szText = appendString(szText,"						<iYield>%s</iYield>" %(objBuildingInfo.getBonusYieldModifier(iI, iJ)))
					szText = appendString(szText,"					</YieldModifiers>")
					szText = appendString(szText,"				</BonusYieldModifier>")
			szText = appendString(szText,"			</BonusYieldModifiers>")
		else:
			szText = appendString(szText,"			<BonusYieldModifiers/>")
		
		if(self.isFlavorsDefined(iBuilding)):
			szText = appendString(szText,"			<Flavors>")
			for iI in range(gc.getNumFlavorTypes()):
				if(objBuildingInfo.getFlavorValue(iI) != 0):
					szText = appendString(szText,"				<Flavor>")
					szText = appendString(szText,"					<FlavorType>%s</FlavorType>" %(gc.getFlavorTypes(iI)))
					szText = appendString(szText,"					<iFlavor>%s</iFlavor>" %(objBuildingInfo.getFlavorValue(iI)))
					szText = appendString(szText,"				</Flavor>")
			szText = appendString(szText,"			</Flavors>")
		else:
			szText = appendString(szText,"			<Flavors/>")

		if(len(objBuildingInfo.getHotKey()) > 0):
			szText = appendString(szText,"			<HotKey>%s</HotKey>" %(objBuildingInfo.getHotKey()))
		else:
			szText = appendString(szText,"			<HotKey/>")
		
		szText = appendString(szText,"			<bAltDown>%s</bAltDown>" %(boolToInt(objBuildingInfo.isAltDown())))
		szText = appendString(szText,"			<bShiftDown>%s</bShiftDown>" %(boolToInt(objBuildingInfo.isShiftDown())))
		szText = appendString(szText,"			<bCtrlDown>%s</bCtrlDown>" %(boolToInt(objBuildingInfo.isCtrlDown())))
		szText = appendString(szText,"			<iHotKeyPriority>%s</iHotKeyPriority>" %(objBuildingInfo.getHotKeyPriority()))
		if(objBuildingInfo.getOrderPriority() != 5):
			szText = appendString(szText,"			<iOrderPriority>%s</iOrderPriority>" %(objBuildingInfo.getOrderPriority()))

		szText = appendString(szText,"		</BuildingInfo>")
			
		return szText

						
	def printBuildings(self):	
	
		strSavePath = ""
		strFileSavePath = ""
		strModPath = ""
		strModAssetPath = ""
		strModAssetSavePath = ""
		strModAssetPath = ""
		
		if(os.access(CvPath.userActiveModDir,os.F_OK)):
			strModPath = CvPath.userActiveModDir
		elif(os.access(CvPath.installActiveModDir,os.F_OK)):
			strModPath = CvPath.installActiveModDir
		else:
			self.dataSavePopup(false)
			return
			
		strSavePath = "%s\%s" %(strModPath,g_strSaveDirectoryLocation)
		strModAssetPath = "%s\\Assets\\" %(strModPath)
		
		if(g_bCreateAssetHierarchy):
			strSavePath += "\Assets\XML\Buildings" 

		strFileSavePath = "%s\%s" %(strSavePath, "CIV4BuildingInfos.xml")

		try:
			if(os.access(strSavePath,os.F_OK)):
				if(os.access(strFileSavePath,os.F_OK)):
					os.remove(strFileSavePath)
				os.removedirs(strSavePath)
		except:
			pass
			
		if(not os.access(strSavePath,os.F_OK)):
			os.makedirs(strSavePath)

							
		szText = "<?xml version=\"1.0\"?>"
		szText = appendString(szText,"<!-- Created by Tech Civilizeditor %s by TheLopez-->" %(editorVersion()))
		szText = appendString(szText,"<!-- Sid Meier's Civilization 4 -->")
		szText = appendString(szText,"<!-- Copyright Firaxis Games 2005 -->")
		szText = appendString(szText,"<!-- -->")
		szText = appendString(szText,"<!-- Building Infos -->")
		szText = appendString(szText,"<Civ4BuildingInfos xmlns=\"x-schema:CIV4BuildingsSchema.xml\">")
		szText = appendString(szText,"	<BuildingInfos>")
				
		for iBuilding in range(gc.getNumBuildingInfos()):

			if(gc.getBuildingInfo(iBuilding).isDeleted()):
				continue

			szText = appendString(szText,self.printBuilding(iBuilding))
			
						
		szText = appendString(szText,"	</BuildingInfos>")
		szText = appendString(szText,"</Civ4BuildingInfos>")

			
		fd = os.open(strFileSavePath, os.O_CREAT)
		os.close(fd)

		fd = os.open(strFileSavePath, os.O_RDWR)
		os.write(fd, szText)
		os.close(fd)
		
		if(g_bSaveChangesInEditorAssetsDirectory):
			strModAssetPath = "%s\%s" %(strModPath,"\Assets\XML\Buildings")
			strModAssetSavePath = "%s\%s" %(strModPath, "\Assets\XML\Buildings\CIV4BuildingInfos.xml")
			try:
				if(os.access(strModAssetPath,os.F_OK)):
					if(os.access(strModAssetSavePath,os.F_OK)):
						os.remove(strModAssetSavePath)
			except:
				pass
			
			if(not os.access(strModAssetPath,os.F_OK)):
				os.makedirs(strModAssetPath)

			fd = os.open(strModAssetSavePath, os.O_CREAT)
			os.close(fd)

			fd = os.open(strModAssetSavePath, os.O_RDWR)
			os.write(fd, szText)
			os.close(fd)
	

